from tools.base_page import BasePage


class ShengyaTeacher(BasePage):

    def yuyue_teacher(self, name, phone, school, major, question_data):
        first_teacher = ('xpath',
                         '//*[@resource-id="com.znb.zxx:id/teacher_list_recycle"]/android.view.ViewGroup[1]/android.widget.TextView[1]')
        yijianyuyue = ('id', 'submit_tv')
        name_locator = ('id', 'name_edit')
        phone_locator = ('id', 'phone_edit')
        school_locator = ('id', 'school_edit')
        major_locator = ('id', 'major_edit')
        finish = ('xpath', '//*[@text="完成"]')
        reply_date = ('id', 'time_edit')
        question_edit = ('id', 'question_edit')
        yuyue = ('id', 'submit_tv')

        self.find(first_teacher).click()
        self.find(yijianyuyue).click()
        self.find(name_locator).send_keys(name)
        self.find(phone_locator).send_keys(phone)
        self.find(school_locator).send_keys(school)
        self.find(major_locator).send_keys(major)
        self.find(reply_date).click()
        self.find(finish).click()
        self.find(question_edit).send_keys(question_data)
        self.find(yuyue).click()
        if self.is_element(("xpath", "//*[@text='一键预约']")) == True:
            print("预约成功")
            self.page(self.index)
            return True
        else:
            print("填写信息有误")
            self.page(self.index)
            return False
